#include<bits/stdc++.h>
using namespace std;
int d[100010],u[100010],a[100010],p[100010];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        int n,m,l,v,ans=0;
        cin>>n>>m>>l>>v;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>u[i]>>a[i];
        }
        for(int i=1;i<=n;i++){
            cin>>p[i];
        }
        for(int i=1;i<=n;i++){
            if(u[i]>v){
                ans++;
            }
        }
        cout<<ans<<" "<<m-1<<endl;
    }
}